﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.serverpackets;
using l1cs.server.model;

namespace l1cs.server.clientpackets
{
    public class C_Emblem : ClientBasePacket
    {
        private const String _C_EMBLEM = "[C] C_Emblem";
        private static Logger _log = Logger.getLogger( typeof( C_Emblem ).FullName );

        public C_Emblem( byte[] abyte0, ClientThread clientthread )
            : base( abyte0 )
        {

            L1PcInstance player = clientthread.getActiveChar();
            if ( player.getClanid() != 0 )
            {
                String emblem_file = Convert.ToString( player.getClanid() );

                // TODO 優先度5 エンブレムの保存方法
                //FileOutputStream fos = null;
                //try
                //{
                //    fos = new FileOutputStream( "emblem/" + emblem_file );
                //    for ( short cnt = 0; cnt < 384; cnt++ )
                //    {
                //        fos.write( readC() );
                //    }
                //}
                //catch ( Exception e )
                //{
                //    _log.log( Level.SEVERE, e.getLocalizedMessage(), e );
                //    throw e;
                //}
                //finally
                //{
                //    if ( null != fos )
                //    {
                //        fos.close();
                //    }
                //    fos = null;
                //}
                player.sendPackets( new S_Emblem( player.getClanid() ) );
                // player.broadcastPacket(new S_Emblem(player.getClanid()));
                L1World.getInstance().broadcastPacketToAll(
                        new S_Emblem( player.getClanid() ) );
            }
        }

        override
        public String getType()
        {
            return _C_EMBLEM;
        }
    }
}
